import React, {PureComponent} from 'react';

class Index extends PureComponent {
    state = {
        carName: '宝马X8',
        arr: ['李小龙']
    }

    change = () => {
        let {arr} = this.state;
        this.setState({
            arr: ['里飞鸿', ...arr]
        })
    }

    render() {
        let {carName, arr} = this.state;
        return (
            <div>
                <h3>我是父组件</h3>
                <h3>我的车是{carName},{arr}</h3>
                <button onClick={this.change}>换车</button>
                <Child carName={carName}/>
            </div>
        );
    }
}

export default Index;


class Child extends PureComponent {
    render() {
        return (
            <div>
                <h3>我是子组件</h3>
                {/*<h3>我的车是{this.props.carName}</h3>*/}
            </div>
        );
    }
}